import java.util.Arrays;

public class Solution1340 {
    public int maxJumps(int[] arr, int d) {
        int[] f=new int[arr.length];
        Arrays.fill(f,-1);
        for (int i=0;i<arr.length;i++){
            dfs(arr,f,d,i);
        }
        return Arrays.stream(f).max().getAsInt();
    }

    private void dfs(int[] arr, int[] f, int d,int t) {
        if (f[t]!=-1){
            return;
        }
        f[t]=1;
        int now=t-1;
        while (now>=t-d && now>=0){
            if (arr[now]<arr[t]){
                dfs(arr,f,d,now);
                f[t]=Math.max(f[t],f[now]+1);
                now--;
            }else {
                break;
            }
        }
        now=t+1;
        while (now<=t+d && now<arr.length){
            if (arr[now]<arr[t]){
                dfs(arr,f,d,now);
                f[t]=Math.max(f[t],f[now]+1);
                now++;
            }else {
                break;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution1340().maxJumps(new int[]{6,4,14,6,8,13,9,7,10,6,12},2));
    }
}
